package com.googlecode.bbs.server.pipeline;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;

import com.googlecode.bbs.server.domain.BBSMessage;
import com.googlecode.bbs.server.mananger.BBSManage;
import com.googlecode.bbs.server.worker.MessageWorker;

public class BizProcesser extends  SimpleChannelUpstreamHandler{

	private Executor messageWorkers = Executors.newFixedThreadPool(20);

	private BBSManage bbsManager;
	
	public BizProcesser(com.googlecode.bbs.server.mananger.BBSManage bbSManage) {
		super();
	}

	@Override
	public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
			throws Exception {
		super.messageReceived(ctx, e);
		BBSMessage msg = (BBSMessage) e.getMessage();
		messageWorkers.execute(new MessageWorker(bbsManager, msg));
	}
	
}
